package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.component.util.DateUtil;
import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.pubdef.dto.user.UserContentAdminSearchConditionDTO;
import com.qumitech.visualnovel.pubdef.dto.user.UserContentRecordAdminDTO;
import com.qumitech.visualnovel.service.user.UserContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ywxie
 * @date 2019/9/23 13:54
 * @description
 */
@RestController
@RequestMapping("/api/admin/usercontent")
public class UserContentController {

    @Autowired
    private UserContentService userContentService;
    @Autowired
    DateUtil dateUtil;

    @GetMapping()
    public BaseRsp getUserContent(UserContentAdminSearchConditionDTO dto){
        Map<String, String> paramMap = new HashMap<>();
        if (dto.getLimit() != null){
            paramMap.put("limit", dto.getLimit().toString());
        }
        if (dto.getOffset() != null){
            paramMap.put("offset", dto.getOffset().toString());
        }
        if(dto.getUid() != null){
            paramMap.put("uid", dto.getUid().toString());
        }
        if(dto.getContentType() != null){
            paramMap.put("content_type", dto.getContentType().toString());
        }
        if(dto.getAutoAuditState() != null){
            paramMap.put("auto_audit_state", dto.getAutoAuditState().toString());
        }
        if(dto.getManualAuditState() != null){
            paramMap.put("manual_audit_state", dto.getManualAuditState().toString());
        }
        if(dto.getStartTime() != null){
            paramMap.put("start_time", dto.getStartTime());
        }
        if(dto.getEndTime() != null){
            paramMap.put("end_time", dto.getEndTime());
        }
        return new BaseRsp(ResultEnum.SUCCESS, userContentService.listUserContentByConditions(paramMap));
    }

    @PutMapping("")
    public BaseRsp updateUserContentAdmin(@RequestBody UserContentRecordAdminDTO dto) {
        userContentService.updateUserContentAdmin(dto);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

}
